/*
 * @userName: 湫之恋
 * @Author: Seven
 * @Date: 2020-06-30 14:04:49
 * @LastEditors: Seven
 * @LastEditTime: 2020-07-02 11:12:07
 */
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var jwtAuth = require("./utils/jwt");

require("./dao/database");

var indexRouter = require('./routes/index');
var orderRouter = require('./routes/order/order');
// var usersRouter = require('./routes/user');
// var pAdminRouter = require('./routes/pAdmin');
var adminRouter = require('./routes/admin/admin')//配置管理员的一级路由
var carRouter=require('./routes/car/carroutes');//引入车辆一级路径
// var usersRouter = require('./routes/user');
var usersRouter = require('./routes/user/users');
var estimatesRouter = require('./routes/estimate/estimate');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(jwtAuth)

app.use('/', indexRouter);
//订单接口
app.use('/order', orderRouter);
app.use('/estimate', estimatesRouter);
app.use('/admin', adminRouter);//配置管理员的一级路由
app.use('/user', usersRouter);
app.use('/car',carRouter);//车辆接口


// catch 404 and forward to error handler
app.use(function (req, res, next) {
  next(createError(404));
});

// error handler
app.use(function (err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};
  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

// module.exports = app;
app.listen(3003, () => { console.log("3003端口启动成功") })